/* Represents the Player. Contains information and properties of the player. This is what is directly loaded and saved to the .sav
 * file. 
 */

package game;

import item.*;
import item.defensive.*;
import item.drone.*;
import item.engine.*;
import item.ship.*;
import item.weapon.*;

import java.io.*;
import java.util.*;

import map.*;

public class Player implements Serializable{
	
	private static final long serialVersionUID = -3112045320722216789L;
	private int level; //the "level" of the game goes up after exploring each new sector
	private int year; //the current year used purely for atmosphere purposes
	private String name; //the name of the player and also the name of the save
	private int fuel; //the amount of fuel the player has
	private int credits; //the amount of credits acquired
	private int scrap; //the amount of scrap acquired
	private int maxFleet; //the max amount of ships //THIS MAY BE MADE FINAL IF THE MAX NUMBER OF SHIPS YOU CAN HAVE CHANGES
	private ArrayList<Ship> fleet; //the fleet of ships
	private Inventory inventory; //the player's current inventory
	private Location location; //the player's current location
	private Difficulty difficulty;
	
	
	//1 param constructor that just sets the name of the player to the specified string and default values for everything else
	public Player(String n){
		
		level = 1;
		year = 2150;
		name = n;
		fuel = 100;
		credits = 1000;
		scrap = 100;
		maxFleet = 4;
		fleet = new ArrayList<Ship>();
		inventory = new Inventory();
		location = new Location();
		difficulty = Difficulty.NORMAL;
	}//String constructor
	

	//2 param constructor that just sets the name of the player to the specified string and resource values adjusted for difficulty
	public Player(String n, Difficulty d){
		
		level = 1;
		year = 2150;
		name = n;
		fuel = 100;
		credits = (int)Math.floor(1000 * d.resourceMultiplier);
		scrap = (int)Math.floor(100 * d.resourceMultiplier);
		maxFleet = 4;
		fleet = new ArrayList<Ship>();
		inventory = new Inventory();
		location = new Location();
		difficulty = d;
	}//String Difficulty constructor
	
	
	//returns the name of this object
	public String getName(){
		
		return name;
	}//getName
	
	
	//adds one to the level
	public void levelUp(){
		
		level++;
	}//levelUp
	
	//returns the current number of ships
	public int getNumShips(){
		
		return fleet.size();
	}//getNumShips
	
	
	//adds a ship to the fleet. Returns the index the ship was added to and -1 if the fleet is full
	public int addShip(Ship s){
		
		if(fleet.size() == maxFleet)
			return - 1;
		
		fleet.add(s);
		return fleet.size() - 1;
	}//addShip
	
	
	//switches the ships at the two positions f and s
	public void switchShips(int f, int s){
		
		Ship temp = fleet.get(s); //temporary ship used for switching
		
		fleet.set(s, fleet.get(f));
		fleet.set(f, temp);
	}//switchShips
	
	
	//represents and inventory and contains the weapons, shields, and drones the player has
	private class Inventory implements Serializable{

		private static final long serialVersionUID = 5246836674387151108L;
		private ArrayList<Weapon> weapons;
		private ArrayList<Shield> shields;
		private ArrayList<Drone> drones;
		private ArrayList<Engine> engines;
		
		
		//0 param constructor that creates an empty inventory
		public Inventory(){
			
			weapons = new ArrayList<Weapon>();
			shields = new ArrayList<Shield>();
			drones = new ArrayList<Drone>();
			engines = new ArrayList<Engine>();
		}//default constructor
		
	}//Inventory
	
	
	//represents the current the location the player is at
	private class Location implements Serializable{

		private static final long serialVersionUID = 5706117103727635711L;
		private int node; //the nodeID of the current node
		private int sector; //the sectorID of the current sector
		private int galaxy; //the galaxyID of the current Galaxy
		
		
		//0 param constructor that sets the location to the default starting location
		public Location(){
			
			node = 0;
			sector = 0;
			galaxy = 0;
		}//default constructor
		
		
	}//Location
}//Player